package com.xujl.utilslibrary.data;

import com.xujl.utilslibrary.view.ViewTool;

/**
 * Created by xujl on 2018/1/19.
 * 类型判断工具类，只能判断基础数据类型和String，List
 */

public class TypeUtils {
    public static final int TYPE_UNKNOW = -1;
    public static final int TYPE_INT = 0;
    public static final int TYPE_STRING = 1;
    public static final int TYPE_LONG = 2;
    public static final int TYPE_SHORT = 3;
    public static final int TYPE_CHAR = 4;
    public static final int TYPE_BYTE = 5;
    public static final int TYPE_FLOAT = 6;
    public static final int TYPE_DOUBLE = 7;
    public static final int TYPE_BOOLEAN = 8;
    public static final int TYPE_LIST = 9;

    private static final String STRING_CLASS = "java.lang.String";
    private static final String INTEGER_CLASS = "java.lang.Integer";
    private static final String LONG_CLASS = "java.lang.Long";
    private static final String SHORT_CLASS = "java.lang.Short";
    private static final String CHART_CLASS = "java.lang.Character";
    private static final String BYTE_CLASS = "java.lang.Byte";
    private static final String FLOAT_CLASS = "java.lang.Float";
    private static final String DOUBLE_CLASS = "java.lang.Double";
    private static final String BOOLEAN_CLASS = "java.lang.Boolean";
    private static final String LIST_CLASS = "java.util.List";

    private static final String BASE_INTEGER_CLASS = "int";
    private static final String BASE_LONG_CLASS = "long";
    private static final String BASE_SHORT_CLASS = "short";
    private static final String BASE_CHART_CLASS = "char";
    private static final String BASE_BYTE_CLASS = "btye";
    private static final String BASE_FLOAT_CLASS = "float";
    private static final String BASE_DOUBLE_CLASS = "double";
    private static final String BASE_BOOLEAN_CLASS = "boolean";

    /**
     * 获取字段类型
     * @param typeName
     * @return
     */
    public static int getType (String typeName) {
        if (ViewTool.isEmpty(typeName)) {
            return TYPE_UNKNOW;
        }
        if (typeName.equals(STRING_CLASS)) {
            return TYPE_STRING;
        }
        if (typeName.equals(INTEGER_CLASS) || typeName.equals(BASE_INTEGER_CLASS)) {
            return TYPE_INT;
        }
        if (typeName.equals(LONG_CLASS) || typeName.equals(BASE_LONG_CLASS)) {
            return TYPE_LONG;
        }
        if (typeName.equals(SHORT_CLASS) || typeName.equals(BASE_SHORT_CLASS)) {
            return TYPE_SHORT;
        }
        if (typeName.equals(BYTE_CLASS) || typeName.equals(BASE_BYTE_CLASS)) {
            return TYPE_BYTE;
        }
        if (typeName.equals(FLOAT_CLASS) || typeName.equals(BASE_FLOAT_CLASS)) {
            return TYPE_FLOAT;
        }
        if (typeName.equals(BOOLEAN_CLASS) || typeName.equals(BASE_BOOLEAN_CLASS)) {
            return TYPE_BOOLEAN;
        }
        if (typeName.equals(LIST_CLASS)) {
            return TYPE_LIST;
        }
        if (typeName.equals(DOUBLE_CLASS) || typeName.equals(BASE_DOUBLE_CLASS)) {
            return TYPE_DOUBLE;
        }
        if (typeName.equals(CHART_CLASS) || typeName.equals(BASE_CHART_CLASS)) {
            return TYPE_CHAR;
        }
        return TYPE_UNKNOW;
    }
}
